package com.atwei.mango.system.account.service.impl;

import com.atwei.mango.system.account.entity.AccountRole;
import com.atwei.mango.system.account.entity.RoleRes;
import com.atwei.mango.system.account.mapper.AccountRoleMapper;
import com.atwei.mango.system.account.mapper.RoleResMapper;
import com.atwei.mango.system.account.service.RoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Classname ResService
 * @Description
 * @Date 2022/6/10 14:52
 * @Author liuwei
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private AccountRoleMapper accountRoleMapper;
    @Resource
    private RoleResMapper roleResMapper;

    @Override
    public List<Integer> getRolesByAccountId(Integer accountId) {
        QueryWrapper<AccountRole> query = Wrappers.query();
        query.select("role_id");
        query.eq("account_id",accountId);
        List<Object> objects = accountRoleMapper.selectObjs(query);
        return objects.stream().map(o -> (Integer)o).collect(Collectors.toList());
    }

    @Override
    public List<Integer> getRessByRoleIds(List<Integer> roleIds) {
        QueryWrapper<RoleRes> query = Wrappers.query();
        query.select("res_id");
        query.in("role_id",roleIds);
        List<Object> objects = roleResMapper.selectObjs(query);
        return objects.stream().map(o -> (Integer)o).collect(Collectors.toList());
    }


}
